package com.tiza.xiaoyoubao.app;

import android.content.Context;

import com.jakewharton.picasso.OkHttp3Downloader;
import com.orhanobut.hawk.Hawk;
import com.squareup.picasso.Picasso;
import com.tianze.library.base.BaseApplication;
import com.zhy.http.okhttp.OkHttpUtils;

import org.litepal.LitePalApplication;

import okhttp3.OkHttpClient;

/**
 * Created by mapple on 17/2/13.
 */

public class AppContext extends BaseApplication {

    private static AppContext instance;
    /**
     * 登录状态
     */
    private boolean isLogin = false;
    //接单声音
    private boolean isSound=true;
    private boolean isVibration=true;

    private static OkHttpClient sHttpClient;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        // 自定义缓存
        sHttpClient = OkHttpUtils.getInstance()
                                 .getOkHttpClient();
        Picasso picasso = new Picasso.Builder(this).downloader(new OkHttp3Downloader(sHttpClient))
                                                   .build();
        Picasso.setSingletonInstance(picasso);
        LitePalApplication.initialize(this);
        AppConfig.Init(this);
    }

    public static AppContext getInstance() {
        return instance;
    }

    public static Context getContext() {
        return sContext.getApplicationContext();
    }


    public boolean isLogin() {
        return isLogin;
    }

    public void setLogin(boolean login) {
        isLogin = login;
    }
    public boolean isSound() {
        return isSound;
    }

    public void setSound(boolean pSound) {
        isSound = pSound;
        Hawk.put(Constants.KEY_SOUND, isSound);
    }
    public boolean isVibration() {
        return isVibration;
    }

    public void setVibration(boolean pVibration) {
        isVibration = pVibration;
        Hawk.put(Constants.KEY_VIBRATION, isVibration);
    }
}
